﻿using SoldiHive.Infrustructure.Extensions;
using System;
using System.Collections.Generic;

namespace SoldiHive.Model.Views
{
	[Serializable]
	public class ResponseView
	{
		public EarningsStatement PastEarningsStatement { get; set; }
		public IList<Quote> Quotes { get; set; }

		public ResponseView(EarningsStatement pastEarningsStatement, IList<Quote> quotes)
		{
			this.PastEarningsStatement = pastEarningsStatement;
			this.Quotes = quotes;
		}

		public override string ToString()
		{
			var priceChanges = new List<string>();
			Quote previousQuote = null;
			foreach (var quote in this.Quotes)
			{
				if (previousQuote != null)
				{
					var priceChange = string.Format("{0}{1:0.00}%",
						previousQuote.Close < quote.Open ? "▲" : "▼",
						Math.Abs((quote.Open - previousQuote.Close) / previousQuote.Close) * 100).Align(7);

					priceChanges.Add(priceChange);
				}

				previousQuote = quote;
			}

			var priceChangesString = string.Join(" ", priceChanges);

			var responseViewString = string.Format("{0} {1:Date}", 
				priceChangesString, 
				this.PastEarningsStatement);

			return responseViewString;
		}
	}
}
